package com.social.dao;


import com.social.pojo.es.EsActivity;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @author zero
 */
@Repository
@SuppressWarnings("all")
public interface EsActivityRepository extends ElasticsearchRepository<EsActivity, String> {
    //根据title和description查询产品,注意函数名称里面的名称一定要和属性名称一致，否则会报错
    List<EsActivity> findByTitleOrContent(String title, String content);

    @Highlight(fields = {
            @HighlightField(name = "title")
    })
    @Query("{\"match\":{\"title\":\"?0\"}}")
    SearchHits<EsActivity> findTitle(String keyword);

    @Highlight(fields = {
            @HighlightField(name = "title"),
            @HighlightField(name = "content")
    })
    @Query("{\"bool\":" +
            "{\"should\":[" +
            "{\"term\":{\"title\": \"?0\"}}," +
            "{\"term\":{\"content\": \"?0\"}}]}}")
    SearchHits<EsActivity> findTitleOrDesc(String keyword);

    List<EsActivity> findAll();

    List<EsActivity> findAllByContentAndAndTitleAndHoster();
}
